/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var cardsUpdate={
	activityUE:null,
	key:null,
		
	startEvent:function(){
		cardsUpdate.showInfo();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/cardsCtrl/update';
				var params = jsUtils.serializeJson($('.com-addForm'));
				//delete params.startTime;
				//delete params.endTime;
				
				
				var cb = function(data){
					alert(data.msg);
					//成功返回
					
					 
					if(data.resultCode==200){
						localStorage.removeItem(cardsUpdate.key);
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfo:function(){
		
		var id = art.dialog.data('updId');
		cardsUpdate.key = id + "_cards_Key";
		
		cardInfo = eval('(' + localStorage.getItem(cardsUpdate.key) + ')');
		
		var cardsType = jsUtils.getDictionaryTxtByType("cardsType", cardInfo.type);
		
		$("input[name='id']").val(cardInfo.id);
		$("input[name='type']").val(cardsType);
		$("input[name='rate']").val(cardInfo.rate);
		$("input[name='cardDesc']").val(cardInfo.cardDesc);
		
		
		var startDate = cardInfo.startDate == null ? '' : (new Date(cardInfo.startDate))
				.format('yyyy-MM-dd');
		 
		
		$("input[name='startDate']").val( startDate);
		
		var endDate = cardInfo.endDate == null ? '' : (new Date(cardInfo.endDate))
				.format('yyyy-MM-dd');
		
		$("input[name='endDate']").val(endDate);
		
		
		var expireDate = cardInfo.expireDate == null ? '' : (new Date(cardInfo.expireDate))
				.format('yyyy-MM-dd');
		
		$("input[name='expireDate']").val(expireDate);
		
		$("input[name='totalNum']").val(cardInfo.totalNum);
		$("input[name='usedNum']").val(cardInfo.usedNum);
		
	 
	},
	
	init:function(){
		cardsUpdate.startEvent();
	}
}
$(document).ready(function() {
	cardsUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}